<?php
/**
 * Created by Auth.php.
 * User: wy
 * Date: 2019/4/10
 * Time: 8:59
 */

namespace app\admin\controller;

use my\Security;
use my\Tools;
use think\Request;
use think\Db;
use app\admin\model\RegionModel;
use app\admin\model\AdminActivity;
use DateTime;
use think\Env;
use app\admin\model\AdminModel;
use app\admin\controller\ProduceCode;

class Auth extends Base
{
    protected $map = [
        'a.record_status'   => ['in', [2, 3]],
        'c.auth_type'       => ['in',[1,3]],
    ];
    protected $region_model;

    public function _initialize()
    {
        parent::_initialize();
        $this->region_model = new RegionModel();
        //身份证信息 fr_driver_base =》 check_driver_result
        $this->driverInfo = ['driver_name', 'id_number', 'id_front', 'id_back', 'id_hold'];
        //驾驶证信息 fr_driver_base =》 check_driver_result
        $this->licenseInfo = ['license_time', 'valid_time', 'license'];
        //车辆信息 fr_car =》 check_car_result
        $this->carInfo = ['car_brand', 'car_model', 'car_color', 'body_img'];
        //行驶证信息 fr_car =》 check_car_result
        $this->permitInfo = ['owner', 'car_plate', 'vin', 'register_at', 'permit'];
        //运营证信息
        $this->certificate = ['taxi', 'taxi_certificate'];
        //保单信息
        $this->insurance = ['commerceinsurance', 'sail', 'carriage'];
        $request = Request::instance();
        $domain = $request->domain();
        if (strpos($domain, 'admin') !== false) {
            $btstatus = 2;
        } else {
            $btstatus = 1;
        }
        $this->zhimaBack = $btstatus;
        $areaInfo = AdminModel::getRoleArea();
        if(!empty($areaInfo)){
            $this->map['c.work_city'] = ['in',implode(',',$areaInfo['city'])];
        }
    }

    //司机认证审核列表
    public function index()
    {
        $page       = input('get.page');
        $limit      = input('get.limit');
        $driver_type= input('get.driver_type');
        if ($page && $limit) {
            $map = $this->map;

            if (input('get.car_plate')) {
                $car_plate = input('get.car_plate');
                $map['a.car_plate'] = Security::encrypt($car_plate);
            }
            if (input('get.driver_phone')) {
                $phone = input('get.driver_phone');
                $map['b.driver_phone'] = Security::encrypt($phone);
            }
            //注册省份
            if (input('get.province_id') != '') {
                $map['c.work_province'] = input('get.province_id');
            }
            //注册城市
            if (input('get.city_id') != '') {
                $map['c.work_city'] = input('get.city_id');
            }
            //司机认证类型
            if(!empty($driver_type)){
                $map['b.driver_type'] = $driver_type;
            }

            $res = Db::name('car_info a')->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
                ->join('driver_back d', 'a.driver_id=d.driver_uid', 'LEFT')->join('xm_region e', 'c.work_province=e.region_id', 'LEFT')
                ->join('xm_region f', 'c.work_city=f.region_id', 'LEFT')
                ->field('a.record_status,a.car_id,a.driver_id,b.driver_name,b.driver_phone,c.auth_type,a.car_plate,a.car_brand,a.car_model,a.color,a.register_at,a.add_time,a.reason,b.auth_status,c.id_number,d.backStatus,a.car_number,c.register_city,e.region_name region_name_province,f.region_name region_name_city,a.car_vin,a.code')
                ->where($map)->page($page, $limit)->order('a.record_status asc,a.add_time desc,a.car_id desc')->select();
            $count = Db::name('car_info a')->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')->where($map)->count();
            $res = decode_array_2($res);
            return json([
                'code' => 0,
                'msg' => '',
                'limit' => $limit,
                'count' => $count,
                'data' => $res
            ]);
        }
        $where = ['parent_id' => 1,'region_level' => 1];
        $provinceList = $this->region_model->getRegion($where, 'region_id,region_name');
        $this->assign('provinceList', $provinceList);
        $this->assign('driver_type', $driver_type);
        return $this->fetch();
    }

    //司机认证编辑
    public function edit()
    {
        if (input('post.')) {
            $postInfo = input('post.');
            $driverInfo = [
                'driver_name' => $postInfo['driver_name'],
            ];
            Db::name("driver_base")->where('driver_id', $postInfo['driver_id'])->update($driverInfo);
            $driverBseInfo = [
                'id_number' => Security::encrypt($postInfo['id_number']),
                'valid_time' => strtotime($postInfo['valid_time']),
                'license_time' => strtotime($postInfo['license_time']),
                'id_front' => Security::encrypt($postInfo['id_front']),
                'id_back' => Security::encrypt($postInfo['id_back']),
                'license' => Security::encrypt($postInfo['license']),
                'permit' => Security::encrypt($postInfo['permit']),
                'body_img' => Security::encrypt($postInfo['body_img'])
            ];
            Db::name("driver_info")->where('driver_id', $postInfo['driver_id'])->update($driverBseInfo);
            $carInfo = [
                'car_plate' => Security::encrypt($postInfo['car_plate']),
                'color' => Security::encrypt($postInfo['color']),
                'owner' => Security::encrypt($postInfo['owner']),
                'vin' => Security::encrypt($postInfo['vin']),
                'car_vin' => Security::encrypt($postInfo['car_vin']),
                'register_at' => strtotime($postInfo['register_at']),
                'update_time' => time()
            ];
            Db::name("car_info")->where('car_id', $postInfo['car_id'])->update($carInfo);
            return "<script type='application/javascript'>alert('修改成功');parent.window.location.reload();</script>";
        } else {
            $car_id = input('get.car_id');
            if ($car_id > 0) {
                $info = Db::name('car_info a')
                    ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
                    ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
                    ->field('a.car_id,a.driver_id,b.driver_name,c.id_number,c.license_time,c.valid_time,a.color,a.owner,a.car_plate,a.vin,a.car_vin,a.register_at,c.id_front,c.id_back,c.license,a.permit,a.body_img')
                    ->where('a.car_id', $car_id)
                    ->find();
                $info = decode_array($info);

                $info['car_vin'] = Security::decrypt($info['car_vin']);
                $this->assign('info', $info);
            }
        }
        return $this->fetch();
    }

    //司机认证待审核显示
    public function auth()
    {
        $car_id = input('get.car_id');
        if ($car_id > 0) {
            $info = Db::name('car_info a')
                ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
                ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
                ->join('driver_back d', 'a.driver_id=d.driver_uid', 'LEFT')
                ->join('region e', 'c.work_province=e.region_id', 'LEFT')
                ->join('region f', 'c.work_city=f.region_id', 'LEFT')
                ->field('a.record_status,b.driver_name,c.id_number,c.id_front,c.id_back,c.id_hold,c.license_time,c.valid_time,c.license,a.car_brand,a.car_model,a.color,a.body_img,a.owner,a.car_plate,a.vin,a.car_vin,a.register_at,a.permit,b.check_driver_result,a.check_car_result,b.auth_status,c.driver_id,a.taxi,a.taxi_certificate,c.auth_type,c.register_city,a.seats,a.company,d.backStatus,d.resultContent,d.time,a.reason,a.car_number,e.region_name as region_name_province,f.region_name as region_name_city,a.code,a.comm_pass,a.sail_pass,a.carriage_pass,a.car_insurance,a.time code_time,a.errorCode,a.errorMsg,a.commerceinsurance_time,a.sail_time,a.carriage_time,a.commerceinsurance,a.sail,a.carriage')
                ->where('a.car_id', $car_id)
                ->find();

            $info = decode_array($info);
            $info['auth_type'] = auth_type()[$info['auth_type']];
            $info['resultContent'] = !empty($info['resultContent']) ? explode(',', $info['resultContent']) : '';
            $info['time'] = !empty($info['time']) ? date("Y-m-d H:i:s", $info['time']) : '';
            if ($info['record_status'] != 1) {
                $info['check_driver_result'] = explode(',', $info['check_driver_result']);
                $info['check_car_result'] = explode(',', $info['check_car_result']);
                $check_arr = array_merge($info['check_driver_result'], $info['check_car_result']);
                $check = [
                    'driverInfo' => 0,   //身份信息
                    'licenseInfo' => 0,   //驾驶证信息
                    'carInfo' => 0,   //车辆信息
                    'permitInfo' => 0,   //行驶证信息
                    'driverDataCheck' => 0
                ];
                //身份信息
                if (in_array('id_number', $check_arr) && in_array('driver_name', $check_arr) && in_array('id_front', $check_arr) && in_array('id_back', $check_arr) && in_array('id_hold', $check_arr)) {
                    $check['driverInfo'] = 1;
                }
                //驾驶证信息
                if (in_array('license_time', $check_arr) && in_array('valid_time', $check_arr) && in_array('license', $check_arr)) {
                    $check['licenseInfo'] = 1;
                }
                //车辆信息
                if (in_array('car_brand', $check_arr) && in_array('car_model', $check_arr) && in_array('car_color', $check_arr) && in_array('body_img', $check_arr)) {
                    $check['carInfo'] = 1;
                }
                //行驶证信息
                if (in_array('owner', $check_arr) && in_array('car_plate', $check_arr) && in_array('register_at', $check_arr) && in_array('permit', $check_arr) && in_array('vin', $check_arr)) {
                    $check['permitInfo'] = 1;
                }
                //司机背景资料
                if (in_array('driverDataCheck', $check_arr)) {
                    $check['driverDataCheck'] = 1;
                }
                //营运车辆运输证与服务资格证
                if (in_array('taxi', $check_arr) && in_array('taxi_certificate', $check_arr)) {
                    $check['certificate'] = 1;
                }
                //车险背调信息操作
                if (!empty($info['code']) && $info['code'] == 200) {
                    $info['car_insurance'] = json_decode($info['car_insurance'], true);
                }
                $info['commerceinsurance'] = Security::decrypt($info['commerceinsurance']);
                $info['sail'] = Security::decrypt($info['sail']);
                $info['carriage'] = Security::decrypt($info['carriage']);
                $config['info'] = $info;
                $config['check'] = $check;
                $config['car_id'] = $car_id;
                $config['car_check_info'] = config('car_check_info');
                $this->assign($config);
            }
        }
        return $this->fetch();
    }


    //司机认证审核提交
    public function ajax_submits()
    {
        $post_car_data = input('post.');     //post获取参数
        $arr = explode('&', $post_car_data['data']);//转成数组
        $post_car = array();
        foreach ($arr as $k => $v) {
            $arr = explode('=', $v);
            $post_car[$arr[0]] = $arr[1];
        }
        $car_id=$post_car['car_id'];
        //查询车辆信息
        $driver_car_info = Db::name('car_info a')
            ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
            ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
            ->field('b.driver_name,b.driver_type,b.driver_phone,a.car_plate,a.car_vin,a.driver_id,c.registration_id,b.check_driver_result')
            ->where('a.car_id', $post_car['car_id'])->find();
        $driver_car_info = decode_array($driver_car_info);
        //更新车辆信息数据 审核结果
        Db::name('car_info')->where('car_id', $post_car['car_id'])->update(['record_status' => $post_car['record_status'], 'reason' => !empty($post_car['reason']) ? $post_car['reason'] : '']);
        //只有第一辆车的时候更新状态
        //$count = Db::name('car_info')->where('driver_id',$post_car['driver_id'])->count();
//        //司机状态有变化时，则更新
//        $check_driver_result_arr = array_merge($this->driverInfo, $this->licenseInfo, ['driverDataCheck']);
//        $check_driver_result = explode(',', $driver_car_info['check_driver_result']);
//        $diff = array_diff($check_driver_result_arr, $check_driver_result);
//        if (!empty($diff)) {
//            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 3]);
//        } else {
//            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 1, 'check_pass_time' => time()]);
//        }
        //通过审核
        if ($post_car['record_status'] == 2) {
            //$this->error('请重新审核提交', '', '', 1);
            return json(['status' => 0, 'msg' => '请重新审核提交']);
        }
        $title = $content = '';
        if ($post_car['record_status'] == 1) {
            $result = [
                'commerceinsurance_time'=> !empty($post_car['commerceinsurance_time']) ? self::date_teim_infomation($post_car['commerceinsurance_time'], 2) : '',
                'sail_time'             => !empty($post_car['sail_time']) ? self::date_teim_infomation($post_car['sail_time'], 2) : '',
                'carriage_time'         => !empty($post_car['carriage_time']) ? self::date_teim_infomation($post_car['carriage_time'], 2) : ''
            ];
            //提交时间
            if (empty($carInfo['commerceinsurance_add'])) {
                $result['commerceinsurance_add'] = time();
            }
            //车辆商业险
            if (!empty($post_car['commerceinsurance'])) {
                $result['commerceinsurance'] = Security::encrypt($post_car['commerceinsurance']);
            }
            //车辆交强险
            if (!empty($post_car['sail'])) {
                $result['sail'] = Security::encrypt($post_car['sail']);
            }
            //车辆承运险
            if (!empty($post_car['carriage'])) {
                $result['carriage'] = Security::encrypt($post_car['carriage']);
            }
            $result['comm_pass'] = 1;
            $result['sail_pass'] = 1;
            $result['carriage_pass'] = 1;
            Db::name('car_info')->where('car_id', $post_car['car_id'])->update($result);
////////////


            //更新司机状态
            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 1, 'check_pass_time' => time()]);
            $data_auth_record['result'] = 1;
            Db::name('driver_base')->where('driver_id', $post_car['driver_id'])->update(['first_pass' => 1]);
            //if(!empty($driver_car_info['car_vin'])){
            //修改车辆在险信息
            //    Db::table('xm_car_info')->where('car_id',$post_car['car_id'])->update(['comm_pass'=>1,'sail_pass'=>1]);
            //}
            $title = "审核通知";
            $content = "恭喜您，车主:{$driver_car_info['driver_name']},车牌:{$driver_car_info['car_plate']},您的认证申请已审核通过，请尽快完善营运证及保单资料，审核通过后即可立即接单";
            $info = ['type' => 'user', 'registration_id' => $driver_car_info['registration_id'], 'uid' => $driver_car_info['driver_id']];
            sendjg($info, $title, $content, 1);
            Tools::sendMes($driver_car_info['driver_phone'], '', 99);

            $driver_type = $driver_car_info['driver_type'];
            //添加 公告消息
            $insert_data['record_id'] = $post_car['driver_id'];
            $insert_data['mes_type'] = 1; //信息类型(1审核通知,2活动通知,3投诉处罚通知,4操作违规处罚通知,5订单完成)
            $insert_data['title'] = "认证通过";
            //$insert_data['content'] = "恭喜您，车主:".$driver_car_info['driver_name']."，车牌:".$driver_car_info['car_plate']."，您的城际司机认证申请已通过，现在可以接单啦";
            $insert_data['send_time'] = time();
            $insert_data['driver_type'] = $driver_type; //司机类型 1快车  2城际
            if($driver_type==1){
                $insert_data['content'] = "恭喜您，车主:".$driver_car_info['driver_name']."，车牌:".$driver_car_info['car_plate']."，您的快车司机认证申请已通过，现在可以接单啦";
            }else{
                $insert_data['content'] = "恭喜您，车主:".$driver_car_info['driver_name']."，车牌:".$driver_car_info['car_plate']."，您的城际司机认证申请已通过，现在可以接单啦";
            }
            $mes_id = Db::table('xm_driver_message')->insertGetId($insert_data);

            //添加司机消息关联表
            $insert_relation_data['driver_id'] = $post_car['driver_id'];
            $insert_relation_data['mes_id'] = $mes_id;
            $insert_relation_data['is_read'] = 2; //是否已读 1是 2否
            $insert_relation_data['is_cancel'] = 2; //是否删除 1删除  2未删除
            Db::table('xm_driver_mes_relation')->insert($insert_relation_data);

        } else if ($post_car['record_status'] == 3) {
            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 3]);
            $data_auth_record['result'] = 2;
            $data_auth_record['reason'] = Tools::mb_truncate($post_car['reason'], 0, 80, '');
            $title = "审核通知";
            $content = "车主:{$driver_car_info['driver_name']},车牌:{$driver_car_info['car_plate']},您的车审核未通过,原因:{$post_car['reason']}";
            //Tools::JPush($title,$content,$driver_car_info['registration_id']);
            $info = array('type' => 'user', 'registration_id' => $driver_car_info['registration_id'], 'uid' => $driver_car_info['driver_id']);
            sendjg($info, $title, $content, 1);
            Tools::sendMes($driver_car_info['driver_phone'], '', 23);
        }
        //更新driver_info表 司机服务分
        $data_driver['service_score'] = config('default_score')['driver_service_score'];
        db('driver_info')->where('driver_id', $data_driver['driver_id'])->update(['service_score' => $data_driver['service_score']]);
        //审核记录
        $data_auth_record['car_id'] = $post_car['car_id'];
        $data_auth_record['driver_id'] = $driver_car_info['driver_id'];
        $data_auth_record['add_time'] = time();
        $data_auth_record['admin_id'] = $_SESSION['admin_id'];
        $data_message['record_id'] = db('driver_auth_record')->insertGetId($data_auth_record);//关联消息表
        //审核记录信息
        $data_message['mes_type'] = 1;//审核通知
        $data_message['title'] = $title;//信息标题
        $data_message['content'] = $content;//信息内容
        $data_message['send_time'] = time();//发送时间
        $data_message['driver_type'] = 2;////司机类型 1快车  2城际
        $data_relation['mes_id'] = Db::name('driver_message')->insertGetId($data_message);//保存信息
        $data_relation['driver_id'] = $driver_car_info['driver_id'];
        db('driver_mes_relation')->insert($data_relation);//保存信息和司机之间的关系

        $config = Db::name('config')->where('id=7')->find();
        if($config['value']=='false'){
            $info_data = Db::name('car_info a')
                ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
                ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
                ->join('driver_back d', 'a.driver_id=d.driver_uid', 'LEFT')
                ->field('a.car_id,a.driver_id,b.driver_name,b.driver_phone,b.compliance_type,c.id_number,c.license_time,c.valid_time,a.car_brand,a.car_model,a.color,a.owner,a.car_plate,a.vin,a.register_at,c.id_front,c.id_back,c.license,a.permit,a.body_img,d.backStatus,d.resultContent,d.time,a.taxi,a.taxi_certificate,a.taxi_pass,a.taxi_certificate_pass,a.taxi_reason,a.commerceinsurance_time,a.sail_time,a.carriage_time,a.comm_pass,a.sail_pass,a.carriage_pass,a.commerceinsurance,a.sail,a.carriage')
                ->where('a.car_id', $car_id)
                ->find();
            $compliance = config('compliance');
            $info_data['compliance_type']=1;
            $info_data['dataStatus']=$post_car['record_status'];
            $res=self::dataCheck2($info_data);
            return $res;
        }else{
            return json(['status' => 1, 'msg' => '操作成功-正在更新司机至交通部!!!']);
        }
    }

    /*public function ajax_submits()
    {
        $post_car_data = input('post.');     //post获取参数
        $arr = explode('&', $post_car_data['data']);//转成数组
        $post_car = array();
        foreach ($arr as $k => $v) {
            $arr = explode('=', $v);
            $post_car[$arr[0]] = $arr[1];
        }
        //查询车辆信息
        $driver_car_info = Db::name('car_info a')
            ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
            ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
            ->field('b.driver_name,b.driver_phone,a.car_plate,a.car_vin,a.driver_id,c.registration_id,b.check_driver_result')
            ->where('a.car_id', $post_car['car_id'])->find();
        $driver_car_info = decode_array($driver_car_info);
        //更新车辆信息数据 审核结果
        Db::name('car_info')->where('car_id', $post_car['car_id'])->update(['record_status' => $post_car['record_status'], 'reason' => !empty($post_car['reason']) ? $post_car['reason'] : '']);
        //只有第一辆车的时候更新状态
        //$count = Db::name('car_info')->where('driver_id',$post_car['driver_id'])->count();
//        //司机状态有变化时，则更新
//        $check_driver_result_arr = array_merge($this->driverInfo, $this->licenseInfo, ['driverDataCheck']);
//        $check_driver_result = explode(',', $driver_car_info['check_driver_result']);
//        $diff = array_diff($check_driver_result_arr, $check_driver_result);
//        if (!empty($diff)) {
//            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 3]);
//        } else {
//            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 1, 'check_pass_time' => time()]);
//        }
        //通过审核
        if ($post_car['record_status'] == 2) {
            //$this->error('请重新审核提交', '', '', 1);
            return json(['status' => 0, 'msg' => '请重新审核提交']);
        }
        $title = $content = '';
        if ($post_car['record_status'] == 1) {
            //更新司机状态
            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 1, 'check_pass_time' => time()]);
            $data_auth_record['result'] = 1;
            Db::name('driver_base')->where('driver_id', $post_car['driver_id'])->update(['first_pass' => 1]);
            //if(!empty($driver_car_info['car_vin'])){
            //修改车辆在险信息
            //    Db::table('xm_car_info')->where('car_id',$post_car['car_id'])->update(['comm_pass'=>1,'sail_pass'=>1]);
            //}
            $title = "审核通知";
            $content = "恭喜您，车主:{$driver_car_info['driver_name']},车牌:{$driver_car_info['car_plate']},您的认证申请已审核通过，请尽快完善营运证及保单资料，审核通过后即可立即接单";
            $info = ['type' => 'user', 'registration_id' => $driver_car_info['registration_id'], 'uid' => $driver_car_info['driver_id']];
            sendjg($info, $title, $content, 1);
            Tools::sendMes($driver_car_info['driver_phone'], '', 99);

            //添加 公告消息
            $insert_data['record_id'] = $post_car['driver_id'];
            $insert_data['mes_type'] = 1; //信息类型(1审核通知,2活动通知,3投诉处罚通知,4操作违规处罚通知,5订单完成)
            $insert_data['title'] = "认证通过";
            $insert_data['content'] = "恭喜您，车主:".$driver_car_info['driver_name']."，车牌:".$driver_car_info['car_plate']."，您的城际司机认证申请已通过，现在可以接单啦";
            $insert_data['send_time'] = time();
            $insert_data['driver_type'] = 2; //司机类型 1快车  2城际
            $mes_id = Db::table('xm_driver_message')->insertGetId($insert_data);

            //添加司机消息关联表
            $insert_relation_data['driver_id'] = $post_car['driver_id'];
            $insert_relation_data['mes_id'] = $mes_id;
            $insert_relation_data['is_read'] = 2; //是否已读 1是 2否
            $insert_relation_data['is_cancel'] = 2; //是否删除 1删除  2未删除
            Db::table('xm_driver_mes_relation')->insert($insert_relation_data);

        } else if ($post_car['record_status'] == 3) {
            Db::name('driver_base')->where("driver_id", $post_car['driver_id'])->update(['auth_status' => 3]);
            $data_auth_record['result'] = 2;
            $data_auth_record['reason'] = Tools::mb_truncate($post_car['reason'], 0, 80, '');
            $title = "审核通知";
            $content = "车主:{$driver_car_info['driver_name']},车牌:{$driver_car_info['car_plate']},您的车审核未通过,原因:{$post_car['reason']}";
            //Tools::JPush($title,$content,$driver_car_info['registration_id']);
            $info = array('type' => 'user', 'registration_id' => $driver_car_info['registration_id'], 'uid' => $driver_car_info['driver_id']);
            sendjg($info, $title, $content, 1);
            Tools::sendMes($driver_car_info['driver_phone'], '', 23);
        }
        //更新driver_info表 司机服务分
        $data_driver['service_score'] = config('default_score')['driver_service_score'];
        db('driver_info')->where('driver_id', $data_driver['driver_id'])->update(['service_score' => $data_driver['service_score']]);
        //审核记录
        $data_auth_record['car_id'] = $post_car['car_id'];
        $data_auth_record['driver_id'] = $driver_car_info['driver_id'];
        $data_auth_record['add_time'] = time();
        $data_auth_record['admin_id'] = $_SESSION['admin_id'];
        $data_message['record_id'] = db('driver_auth_record')->insertGetId($data_auth_record);//关联消息表
        //审核记录信息
        $data_message['mes_type'] = 1;//审核通知
        $data_message['title'] = $title;//信息标题
        $data_message['content'] = $content;//信息内容
        $data_message['send_time'] = time();//发送时间
        $data_message['driver_type'] = 2;////司机类型 1快车  2城际
        $data_relation['mes_id'] = Db::name('driver_message')->insertGetId($data_message);//保存信息
        $data_relation['driver_id'] = $driver_car_info['driver_id'];
        db('driver_mes_relation')->insert($data_relation);//保存信息和司机之间的关系
        return json(['status' => 1, 'msg' => '操作成功-正在更新司机至交通部！']);
    }*/
//快车司机资料审核提交
    public function dataCheck2($data)
    {
        $post_car = $data;
        $result = [
            'commerceinsurance_time'=> $post_car['commerceinsurance_time'],
            'sail_time'             => $post_car['sail_time'],
            'carriage_time'         =>$post_car['carriage_time'],
            'taxi_reason'           => !empty($post_car['remark']) ? $post_car['remark'] : '',
            'id_front'              => $post_car['id_front'],
            'id_back'               => $post_car['id_back'],
            'license'               => $post_car['license'],
            'permit'                => $post_car['permit'],
            'body_img'              => $post_car['body_img']
        ];
        if (!empty($post_car['taxi'])) {
            $result['taxi'] = $post_car['taxi'];
        }
        if (!empty($post_car['taxi_certificate'])) {
            $result['taxi_certificate'] = $post_car['taxi_certificate'];
        }

        //提交时间
        if (empty($carInfo['commerceinsurance_add'])) {
            $result['commerceinsurance_add'] = time();
        }
        //车辆商业险
        if (!empty($post_car['commerceinsurance'])) {
            $result['commerceinsurance'] = $post_car['commerceinsurance'];
        }
        //车辆交强险
        if (!empty($post_car['sail'])) {
            $result['sail'] = $post_car['sail'];
        }
        //车辆承运险
        if (!empty($post_car['carriage'])) {
            $result['carriage'] = $post_car['carriage'];
        }

        if ($post_car['dataStatus'] == 1) {
            $result['auth_time'] = time();
            $result['taxi_pass'] = 1;
            $result['taxi_certificate_pass'] = 1;
            $result['comm_pass'] = 1;
            $result['sail_pass'] = 1;
            $result['carriage_pass'] = 1;
        } else {
            $result['auth_time'] = time();
            $result['taxi_pass'] = 3;
            $result['taxi_certificate_pass'] = 3;
            $result['comm_pass'] = 3;
            $result['sail_pass'] = 3;
            $result['carriage_pass'] = 3;
        }
        Db::name('car_info')->where('car_id', $post_car['car_id'])->update($result);
        Db::name('driver_base')->where('driver_id', $post_car['driver_id'])->update(['compliance_type' => $post_car['compliance_type']]);
        if ($post_car['dataStatus'] == 1) {
            //发送短信
            Tools::sendMes($post_car['driver_phone'], '', 101);
            //查询司机是否为快车司机
            $driver_type = Db::name('driver_base')->where('driver_id', $post_car['driver_id'])->value('driver_type');
            //快车审核通过 - 发放奖励操作
            if($driver_type == 1){
                self::rewardMoney($post_car['driver_id'], $post_car['car_id']);
            }
            //生成小程序二维码
            $produce_code=new ProduceCode();
            $produce_code->produce_code($post_car['driver_id'],$driver_type);
        }
        return json(['status' => 1, 'msg' => '操作成功-正在更新司机至交通部！']);

    }
    //ajax 提交到 java接口
    public function ajax_driver_info()
    {
        $post_car_data = input('post.');     //post获取参数
        $arr = explode('&', $post_car_data['data']);//转成数组
        $post_car = array();
        foreach ($arr as $k => $v) {
            $arr = explode('=', $v);
            $post_car[$arr[0]] = $arr[1];
        }
        //查询车辆信息
        $driver_car_info = Db::name('car_info a')
            ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
            ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
            ->field('b.driver_name,b.driver_phone,a.car_plate,a.driver_id,c.registration_id,b.check_driver_result')
            ->where('a.car_id', $post_car['car_id'])->find();
        $driver_car_info = decode_array($driver_car_info);
        //提交驾驶员移动终端信息 到java交通部接口
        $data_driver_info = Db::table('xm_driver_info')->field('register_ip,license_number')->where('driver_id', $driver_car_info['driver_id'])->find();
        $data_address = json_decode(ip_local_info($data_driver_info['register_ip']), true)['data']['city_id'];
        $data_net_type = Tools::phone_check($driver_car_info['driver_phone']);
        $data_app_version = Db::table('xm_version')->field('ios_num')->order('id DESC')->find();
        //数据组装
        $post_data = [];
        $post_data['CompanyId'] = "3401HMKJ8P2R";
        $post_data['Address'] = intval($data_address);
        $post_data['LicenseId'] = Security::decrypt($data_driver_info['license_number']);
        $post_data['DriverPhone'] = $driver_car_info['driver_phone'];
        $post_data['NetType'] = $data_net_type;
        $post_data['AppVersion'] = $data_app_version['ios_num'];
        $post_data['MapType'] = 2;  // 1 百度地图 2 高德地图 3 其他
        $post_data['State'] = 1;  // 0 无效 1有效
        $post_data['Flag'] = 1;  // 1 新增 2更新 3删除
        $post_data['UpdateTime'] = date('YmdHis', time());
        //提交到java url
        $post_url = Env::get('javaTraffic'.ENV.'_host')."/412";
        return json(['code' => 1, 'msg' => 'success']);
        $res = Tools::request_post($post_url, json_encode($post_data));
        if ($res == 200) {
            return json(['code' => 1, 'msg' => 'success']);
        } else {
            return json(['code' => 0, 'msg' => 'error']);
        }
    }

    //快车司机资料审核列表
    public function indexCheck()
    {
        $page = input('get.page');
        $limit = input('get.limit');
        $driver_type= input('get.driver_type');
        if ($page && $limit) {
            //,'a.taxi_pass'=>['in',[2,3]],'a.taxi_certificate_pass'=>['in',[2,3]]
            $map = $this->map;
            //快车且认证通过的司机 且运营证为待审核和未通过的
            $map['c.auth_type'] = ['in',[1,3]];
            $map['a.record_status'] = 1;
            //注册省份
            if (input('get.province_id') != '') {
                $map['c.work_province'] = input('get.province_id');
            }
            //注册城市
            if (input('get.city_id') != '') {
                $map['c.work_city'] = input('get.city_id');
            }
            if (input('get.car_plate')) {
                $car_plate = input('get.car_plate');
                $map['a.car_plate'] = Security::encrypt($car_plate);
            }
            if (input('get.driver_phone')) {
                $phone = input('get.driver_phone');
                $map['b.driver_phone'] = Security::encrypt($phone);
            }
            if (input('get.driver_name')) {
                $driver_name = input('get.driver_name');
                $map['b.driver_name'] = $driver_name;
            }
            //司机认证类型
            if(!empty($driver_type)){
                $map['b.driver_type'] = $driver_type;
            }
            $order[] = new \think\db\Expression('field(taxi_pass,2,3,1,4,5)');
            //$order[] = new \think\db\Expression('field(sail_pass,2,3,1,4,5)');
            $order[] = new \think\db\Expression('a.taxi_add_time desc');
            $res = Db::name('car_info a')
                ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
                ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
                ->join('xm_region e', 'c.work_province=e.region_id', 'LEFT')
                ->join('xm_region f', 'c.work_city=f.region_id', 'LEFT')
                ->field('a.car_id,a.driver_id,a.comm_pass,a.sail_pass,b.driver_name,b.driver_phone,a.car_plate,a.car_brand,a.car_model,a.color,a.register_at,a.add_time,a.reason,a.taxi_pass,a.taxi_certificate_pass,a.carriage_pass,a.taxi_add_time,a.taxi_reason,e.region_name region_name_province,f.region_name region_name_city')
                ->where($map)
                ->page($page, $limit)
                ->order($order)
                ->select();
            $count = Db::name('car_info a')
                ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
                ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
                ->where($map)
                ->count();
            $res = decode_array_2($res);
            foreach ($res as $key => $value) {
                if ($value['taxi_pass'] == 1 && $value['taxi_certificate_pass'] == 1) {
                    $res[$key]['certificateStatus'] = '<span style="color:green">审核通过</span>';//证书状态审核通过
                } elseif ($value['taxi_pass'] == 3 && $value['taxi_certificate_pass'] == 3) {
                    $res[$key]['certificateStatus'] = '<span style="color:red">审核拒绝</span>';//证书状态审核失败
                } else {
                    $res[$key]['certificateStatus'] = '等待审核';//证书状态等待审核
                }
                if ($value['comm_pass'] == 1 && $value['sail_pass'] == 1 && $value['carriage_pass'] == 1) {
                    $res[$key]['insuranceStatus'] = '<span style="color:green">审核通过</span>';//保单状态审核通过
                } elseif ($value['comm_pass'] == 3 && $value['sail_pass'] == 3 && $value['carriage_pass'] == 3) {
                    $res[$key]['insuranceStatus'] = '<span style="color:red">审核拒绝</span>';//保单状态审核失败
                } elseif ($value['comm_pass'] == 4 || $value['sail_pass'] == 4 || $value['carriage_pass'] == 4) {
                    $res[$key]['insuranceStatus'] = '<span style="color:blue">等待上传</span>';//等待上传
                } elseif ($value['comm_pass'] == 5 || $value['sail_pass'] == 5 || $value['carriage_pass'] == 5) {
                    $res[$key]['insuranceStatus'] = '<span style="color:red">保单过期</span>';//保单过期
                } else {
                    $res[$key]['insuranceStatus'] = '等待审核';//保单状态等待审核
                }
            }
            return json([
                'code' => 0,
                'msg' => '',
                'limit' => $limit,
                'count' => $count,
                'data' => $res
            ]);
        }
        $where = [
            'parent_id' => 1,
            'region_level' => 1
        ];
        $provinceList = $this->region_model->getRegion($where, 'region_id,region_name');
        $this->assign('provinceList', $provinceList);
        $this->assign('driver_type', $driver_type);
        return $this->fetch();
    }

    //审核某个字段
    public function check_one()
    {
        $name = input('post.name');
        $value = input('post.value');
        $car_id = input('post.car_id');
        $carInfo = Db::name('car_info')->where('car_id', $car_id)->find();
        //身份证信息 fr_driver_base =》 check_driver_result
        if ($name == 'driverInfo') {
            $str = $this->driverInfo;
        }
        //驾驶证信息 fr_driver_base =》 check_driver_result
        if ($name == 'licenseInfo') {
            $str = $this->licenseInfo;
        }
        //车辆信息 fr_car =》 check_car_result
        if ($name == 'carInfo') {
            $str = $this->carInfo;
        }
        //行驶证信息 fr_car =》 check_car_result
        if ($name == 'permitInfo') {
            $str = $this->permitInfo;
        }
        //运营证信息
        if ($name == 'certificate') {
            $str = $this->certificate;
        }
        //保单信息
        if ($name == 'insurance') {
            $str = $this->insurance;
        }
        //司机背景资料信息
        if ($name == 'driverDataCheck') {
            $str = ['driverDataCheck'];
        }
        //身份证信息 + 驾驶证信息 =》 fr_driver_base =》 check_driver_result
        if (in_array($name, ['driverInfo', 'licenseInfo', 'driverDataCheck'])) {
            $driverBaseInfo = Db::name('driver_base')->where('driver_id', $carInfo['driver_id'])->find();
            $checkDriver = $driverBaseInfo['check_driver_result'] ? explode(',', $driverBaseInfo['check_driver_result']) : [];
            if ($value == 1) {
                $check_value = $checkDriver ? array_merge($str, $checkDriver) : $str;
            } else {
                $check_value = array_diff($checkDriver, $str);
            }
            $data['check_driver_result'] = implode(',', $check_value);
            if ($name == 'licenseInfo') {
                if ($value == 1) {
                    $license_pic_status = 1;
                } else {
                    $license_pic_status = 3;
                }
                Db::name('driver_info')->where('driver_id', $carInfo['driver_id'])->update(['license_pic_status' => $license_pic_status]);
            }
            Db::name('driver_base')->where('driver_id', $carInfo['driver_id'])->update($data);
        } elseif (in_array($name, ['carInfo', 'permitInfo', 'certificate', 'insurance'])) {//车辆信息 + 行驶证信息 + 运营证信息 + 保单信息 fr_car =》 check_car_result
            $check_value = $carInfo['check_car_result'] ? explode(',', $carInfo['check_car_result']) : [];
            if ($value == 1) {
                $check_value = $check_value ? array_merge($str, $check_value) : $str;
            } else {
                $check_value = array_diff($check_value, $str);
            }
            $result = ['check_car_result' => implode(',', $check_value)];
            //运营证信息
            if ($name == 'certificate') {
                if ($value == 1) {
                    $result['taxi_pass'] = 1;
                    $result['taxi_certificate_pass'] = 1;
                } else {
                    $result['taxi_pass'] = 3;
                    $result['taxi_certificate_pass'] = 3;
                }
            }
            //保险单信息
            if ($name == 'insurance') {
                if ($value == 1) {
                    $result['comm_pass'] = 1;
                    $result['sail_pass'] = 1;
                    $result['carriage_pass'] = 1;
                } else {
                    $result['comm_pass'] = 3;
                    $result['sail_pass'] = 3;
                    $result['carriage_pass'] = 3;
                }
            }
            Db::name('car_info')->where('car_id', $car_id)->update($result);
        } else {
            //出租车更新运营证，快车不更新
            $auth_type = Db::name('driver_info')->where('driver_id', $carInfo['driver_id'])->getField('auth_type');
            if ($auth_type == 2) {//出租车
                if ($value == 1) {
                    Db::name('driver_base')->where('driver_id', $carInfo['driver_id'])->update(['check_driver_result' => implode(',', array_merge($this->driverInfo, $this->licenseInfo, ['driverDataCheck']))]);
                    Db::name('car_info')->where('car_id', $car_id)->update(['check_car_result' => implode(',', array_merge($this->carInfo, $this->permitInfo, $this->certificate))]);
                    $result['taxi_pass'] = 1;
                    $result['taxi_certificate_pass'] = 1;
                } else {
                    Db::name('driver_base')->where('driver_id', $carInfo['driver_id'])->update(['check_driver_result' => '']);
                    Db::name('car_info')->where('car_id', $car_id)->update(['check_car_result' => '']);
                    $result['taxi_pass'] = 3;
                    $result['taxi_certificate_pass'] = 3;
                }
                Db::name('car_info')->where('car_id', $car_id)->update($result);
                //快车，不更新运营证
            } else {
                if ($value == 1) {
                    //只有第一辆车更新司机信息
                    Db::name('driver_base')->where('driver_id', $carInfo['driver_id'])->update(['check_driver_result' => implode(',', array_merge($this->driverInfo, $this->licenseInfo, ['driverDataCheck']))]);
                    Db::name('car_info')->where('car_id', $car_id)->update(['check_car_result' => implode(',', array_merge($this->carInfo, $this->permitInfo))]);
                } else {
                    Db::name('driver_base')->where('driver_id', $carInfo['driver_id'])->update(['check_driver_result' => '']);
                    Db::name('car_info')->where('car_id', $car_id)->update(['check_car_result' => '']);
                }
            }
        }
        echo json_encode(['code' => 1]);
    }

    //快车司机资料审核页面
    public function check_auth()
    {
        $car_id = input('get.car_id');
        if ($car_id > 0) {
            $info = Db::name('car_info a')
                ->join('driver_base b', 'a.driver_id=b.driver_id', 'LEFT')
                ->join('driver_info c', 'b.driver_id=c.driver_id', 'LEFT')
                ->join('driver_back d', 'a.driver_id=d.driver_uid', 'LEFT')
                ->field('a.driver_id,b.driver_name,b.driver_phone,b.compliance_type,c.id_number,c.license_time,c.valid_time,a.car_brand,a.car_model,a.color,a.owner,a.car_plate,a.vin,a.register_at,c.id_front,c.id_back,c.license,a.permit,a.body_img,d.backStatus,d.resultContent,d.time,a.taxi,a.taxi_certificate,a.taxi_pass,a.taxi_certificate_pass,a.taxi_reason,a.commerceinsurance_time,a.sail_time,a.carriage_time,a.comm_pass,a.sail_pass,a.carriage_pass,a.commerceinsurance,a.sail,a.carriage')
                ->where('a.car_id', $car_id)
                ->find();
            $license_time = $info['license_time'];
            $valid_time = $info['valid_time'];
            $commerceinsurance_time = $info['commerceinsurance_time'];
            $sail_time = $info['sail_time'];
            $carriage_time = $info['carriage_time'];
            unset($info['license_time']);
            unset($info['valid_time']);
            unset($info['commerceinsurance_time']);
            unset($info['sail_time']);
            unset($info['carriage_time']);
            $info = decode_array($info);
            $info['license_time'] = !empty($license_time) ? self::date_teim_infomation($license_time) : '';
            $info['valid_time'] = !empty($valid_time) ? self::date_teim_infomation($valid_time) : '';
            $info['commerceinsurance_time'] = !empty($commerceinsurance_time) ? self::date_teim_infomation($commerceinsurance_time) : '';
            $info['sail_time'] = !empty($sail_time) ? self::date_teim_infomation($sail_time) : '';
            $info['carriage_time'] = !empty($carriage_time) ? self::date_teim_infomation($carriage_time) : '';
            $info['time'] = !empty($info['time']) ? date("Y-m-d H:i:s") : '';
            $info['commerceinsurance'] =$info['commerceinsurance']!=null? Security::decrypt($info['commerceinsurance']):'';
            $info['sail'] =$info['sail']!=null? Security::decrypt($info['sail']):'';
            $info['carriage'] =$info['carriage']!=null? Security::decrypt($info['carriage']):'';
            $config['info'] = $info;
            $config['car_id'] = $car_id;
            $config['car_check_data'] = config('car_check_data');
            $config['compliance'] = config('compliance');         //合规资料状态
            $this->assign($config);
        }
        return $this->fetch();
    }

    //处理时间
    public function date_teim_infomation($time = '', $type = 1)
    { //1时间戳2日期
        if ($type == 1) {
            $obj = new DateTime('@' . $time); // 这里时间戳前要写一个@符号
            $timezone = timezone_open('Asia/HONG_KONG'); // 设置时区
            $obj->setTimezone($timezone);
            return $obj->format("Y-m-d");
        } else {
            $obj = new DateTime($time);
            return $obj->format("U");
        }
    }

    //快车司机资料审核提交
    public function dataCheck()
    {
        $post_car = input('post.');     //post获取参数
        $result = [
            'commerceinsurance_time'=> !empty($post_car['commerceinsurance_time']) ? self::date_teim_infomation($post_car['commerceinsurance_time'], 2) : '',
            'sail_time'             => !empty($post_car['sail_time']) ? self::date_teim_infomation($post_car['sail_time'], 2) : '',
            'carriage_time'         => !empty($post_car['carriage_time']) ? self::date_teim_infomation($post_car['carriage_time'], 2) : '',
            'taxi_reason'           => !empty($post_car['remark']) ? $post_car['remark'] : '',
            'id_front'              => Security::encrypt($post_car['id_front']),
            'id_back'               => Security::encrypt($post_car['id_back']),
            'license'               => Security::encrypt($post_car['license']),
            'permit'                => Security::encrypt($post_car['permit']),
            'body_img'              => Security::encrypt($post_car['body_img'])
        ];
        if (!empty($post_car['taxi'])) {
            $result['taxi'] = Security::encrypt($post_car['taxi']);
        }
        if (!empty($post_car['taxi_certificate'])) {
            $result['taxi_certificate'] = Security::encrypt($post_car['taxi_certificate']);
        }
        //运营证
        if (!empty($post_car['yyzStauts'])) {
            if ($post_car['yyzStauts'] == 3) {
                $result['taxi_pass'] = 3;
                $result['taxi_certificate_pass'] = 3;
            } else {
                $result['taxi_pass'] = 1;
                $result['taxi_certificate_pass'] = 1;
            }
        }
        //提交时间
        if (empty($carInfo['commerceinsurance_add'])) {
            $result['commerceinsurance_add'] = time();
        }
        //车辆商业险
        if (!empty($post_car['commerceinsurance'])) {
            $result['commerceinsurance'] = Security::encrypt($post_car['commerceinsurance']);
        }
        //车辆交强险
        if (!empty($post_car['sail'])) {
            $result['sail'] = Security::encrypt($post_car['sail']);
        }
        //车辆承运险
        if (!empty($post_car['carriage'])) {
            $result['carriage'] = Security::encrypt($post_car['carriage']);
        }
        //保单
        if (!empty($post_car['bdStauts'])) {
            if ($post_car['bdStauts'] == 3) {
                $result['comm_pass'] = 3;
                $result['sail_pass'] = 3;
                $result['carriage_pass'] = 3;
            } else {
                $result['comm_pass'] = 1;
                $result['sail_pass'] = 1;
                $result['carriage_pass'] = 1;
            }
        }
        if ($post_car['dataStatus'] == 1) {
            $result['auth_time'] = time();
            $result['taxi_pass'] = 1;
            $result['taxi_certificate_pass'] = 1;
            $result['comm_pass'] = 1;
            $result['sail_pass'] = 1;
            $result['carriage_pass'] = 1;
        } else {
            $result['auth_time'] = time();
            $result['taxi_pass'] = 3;
            $result['taxi_certificate_pass'] = 3;
            $result['comm_pass'] = 3;
            $result['sail_pass'] = 3;
            $result['carriage_pass'] = 3;
        }
        Db::name('car_info')->where('car_id', $post_car['car_id'])->update($result);
        Db::name('driver_base')->where('driver_id', $post_car['driver_id'])->update(['compliance_type' => $post_car['compliance_type']]);
        if ($post_car['dataStatus'] == 1) {
            //发送短信
            Tools::sendMes($post_car['driver_phone'], '', 101);
            //查询司机是否为快车司机
            $driver_type = Db::name('driver_base')->where('driver_id', $post_car['driver_id'])->value('driver_type');
            //快车审核通过 - 发放奖励操作
            if($driver_type == 1){
                self::rewardMoney($post_car['driver_id'], $post_car['car_id']);
            }
            //生成小程序二维码

            $produce_code=new ProduceCode();
            $produce_code->produce_code($post_car['driver_id'],$driver_type);
        }
        return "<script type='application/javascript'>alert('操作成功');parent.window.location.reload();</script>";
    }

    //活动奖励发放操作
    public function rewardMoney($driver_id = '', $car_id = '')
    {
        //查询用户申请认证时间
        $driverInfo = Db::name('driver_info')->where(['driver_id' => $driver_id])->field('register_time')->find();
        //查询司机的认证城市
        $region_id = Db::name('car_info')->where(['driver_id' => $driver_id, 'car_id' => $car_id])->value('work_city');  //查询司机认证城市
        //判断不为空 并且 申请审核时间不能为空
        if (!empty($driverInfo) && !empty($driverInfo['register_time'])) {
            $time = $driverInfo['register_time'];
            $data['city_id'] = !empty($region_id) ? $region_id : '0';
            //查询推荐邀请人 - 记录
            $inviteInfo = Db::name('driver_invite_record')->where(['invitee_id' => $driver_id, 'status' => 1])->find();
            if ($inviteInfo['inviter_type'] == 1 && (!empty($inviteInfo['integral']) || !empty($inviteInfo['coupon_money']))) {
                return false;
            }
            if ($inviteInfo['inviter_type'] == 2 && !empty($inviteInfo['money'])) {
                return false;
            }
            if (!empty($inviteInfo)) {
                //用户推荐邀请注册司机 + 加盟商-推广员推荐邀请注册司机
                $inviter_type = 0;
                $inviterId = $inviteInfo['inviter_id'];                                                            //推荐人ID
                if ($inviteInfo['inviter_type'] == 1 || $inviteInfo['inviter_type'] == 3) {
                    $inviter_type = 1;                                                                                //针对用户+推广员
                    $phone = Db::name('user')->where(['uid' => $inviterId])->value('user_phone');  //手机号码
                } elseif ($inviteInfo['inviter_type'] == 2) {                                                              //司机推荐邀请注册司机
                    $inviter_type = 2;                                                                                //针对司机
                    $phone = Db::name('driver_base')->where(['driver_id' => $inviterId])->value('driver_phone');  //手机号码
                }
                $phone = Security::decrypt($phone);
                //查询是否存在活动信息
                $couponInfo = Db::name('admin_activity')->where(['start_time' => ['<=', $time], 'end_time' => ['>=', $time], 'order_type' => 1, 'status' => 1, 'activity_model' => 6, 'user_type' => $inviter_type])->where(function ($query) use ($data) {
                    $city = $data['city_id'];
                    $query->whereOr("FIND_IN_SET('$city',region_id)");
                    $query->whereOr(['region_id' => 0]);
                })->order('id desc')->select();
                //判断活动存不存在
                if (!empty($couponInfo)) {
                    foreach ($couponInfo as $key => $value) {
                        //限制不为空 判断 当前时间是否在有效期时间之内
                        if (!empty($value['limit_day'])) {
                            $limitTime = $time + $value['limit_day'] * 24 * 3600;
                        } else {
                            $limitTime = 0;
                        }
                        //当前时间 大于 活动领取奖励限制 责不发奖励
                        if (time() > $limitTime && !empty($limitTime)) {
                            //更新邀请记录状态 =》 失效操作
                            Db::name('driver_invite_record')->where(['invitee_id' => $driver_id])->update(['status' => 3]);
                            return false;
                        } else {
                            //更新邀请记录状态 =》 成功操作
                            Db::name('driver_invite_record')->where(['invitee_id' => $driver_id])->update(['status' => 2]);
                            //乘客 - 开始发放奖励 (积分 + 优惠券)
                            if ($value['user_type'] == 1 && $value['award_type'] == 3) {          //送积分
                                //奖励记录入库
                                $result = [
                                    'xm_admin_activity_id' => $value['id'], 'user_type' => $value['user_type'],
                                    'uid' => $inviterId, 'region_id' => $data['city_id'],
                                    'amount' => $value['amount'], 'order_type' => $value['order_type'],
                                    'add_time' => time(), 'account_status' => 1,
                                    'account_time' => time(), 'notice_status' => 1,
                                    'notice_time' => time(), 'status' => 1,
                                    'activity_model' => $value['activity_model'], 'phone' => $phone,
                                ];
                                Db::name('activity_record')->insertGetId($result);
                                //积分账户余额增加 + 生成积分明细
                                $accountInfo = Db::name('integral_account')->where(['uid' => $inviterId, 'status' => 1])->find();
                                if (!empty($accountInfo)) {//积分账户不为空则更新
                                    $accountArr = [
                                        'amount' => $accountInfo['amount'] + $value['amount'] / 100,
                                        'account_receive_amount' => $accountInfo['account_receive_amount'] + $value['amount'] / 100,
                                        'total_receive_amount' => $accountInfo['total_receive_amount'] + $value['amount'] / 100,
                                    ];
                                    Db::name('integral_account')->where(['uid' => $inviterId])->update($accountArr);
                                    $integral_account_id = $accountInfo['id'];
                                } else {//积分账户为空插入数据
                                    $accountArr = [
                                        'uid' => $inviterId,
                                        'amount' => $value['amount'] / 100,
                                        'account_receive_amount' => $value['amount'] / 100,
                                        'total_receive_amount' => $value['amount'] / 100,
                                        'add_time' => time()
                                    ];
                                    $integral_account_id = Db::name('integral_account')->insertGetId($accountArr);
                                }
                                //生成积分记录
                                $recordArr = [
                                    'integral_account_id' => $integral_account_id, 'uid' => $inviterId,
                                    'type' => 4, 'amount' => $value['amount'] / 100,
                                    'status' => 1, 'add_time' => time(),
                                    'account_time' => time()
                                ];
                                Db::name('integral_record')->insertGetId($recordArr);
                                //更新邀请记录奖励积分
                                Db::name('driver_invite_record')->where(['invitee_id' => $driver_id, 'id' => $inviteInfo['id']])->update(['integral' => $value['amount']]);
                            } elseif ($value['user_type'] == 1 && $value['award_type'] == 2) {                             //优惠券
                                //查询优惠券信息
                                $couponList = Db::name('admin_coupon')->where(['admin_activity_id' => $value['id']])->select();
                                $adminActivityModel = new AdminActivity();
                                //开始发放优惠券
                                $adminCouponInfo = [];
                                $couponMoney = '';
                                foreach ($couponList as $kly => $vaml) {
                                    $adminActivityModel->supplyCoupon($vaml['coupon_id'], [$phone], $region_id, $value['order_type'], $inviter_status = 1);
                                    $adminCouponInfo = Db::name('admin_coupon')->where(['coupon_id' => $vaml['coupon_id'], 'status' => 1])->find();
                                    $couponMoney += !empty($adminCouponInfo['limit_num']) ? $adminCouponInfo['money'] * $adminCouponInfo['limit_num'] : $adminCouponInfo['money'] * 1;
                                }
                                Db::name('driver_invite_record')->where(['invitee_id' => $driver_id, 'id' => $inviteInfo['id']])->update(['coupon_money' => $couponMoney]);
                            } elseif ($value['user_type'] == 1 && $value['award_type'] == 1) {                             //乘客 - 现金
                                //奖励记录入库
                                $result = [
                                    'xm_admin_activity_id' => $value['id'], 'user_type' => $value['user_type'],
                                    'uid' => $inviterId, 'region_id' => $data['city_id'],
                                    'amount' => $value['amount'], 'order_type' => $value['order_type'],
                                    'add_time' => time(), 'account_status' => 1,
                                    'account_time' => time(), 'notice_status' => 1,
                                    'notice_time' => time(), 'status' => 1,
                                    'activity_model' => $value['activity_model'], 'phone' => $phone,
                                ];
                                Db::name('activity_record')->insertGetId($result);
                                //流水记录入库
                                $userRecharge = [
                                    'uid' => $inviterId,
                                    'money' => $value['amount'],
                                    'money_statement' => 12,
                                    'time' => time(),
                                    'status' => 1,
                                ];
                                Db::name('user_recharge')->insertGetId($userRecharge);
                                Db::name('user_wallet')->where(['uid' => $inviterId])->setInc('wallet_money', $value['amount']);
                                //通知记录入库
                                $amount = $value['amount'] / 100;
                                $message = [
                                    'uid' => $inviterId,
                                    'title' => '邀请司机认证',
                                    'status' => 1,
                                    'is_read' => 0,
                                    'content' => '邀请司机认证活动奖励' . $amount . '元',
                                    'send_time' => time(),
                                    'type' => 1,
                                    'order_type' => $value['order_type']
                                ];
                                Db::name('passenger_message')->insertGetId($message);
                            } elseif ($value['user_type'] == 2 && $value['award_type'] == 1) {                             //司机发放奖励 - 现金
                                //奖励记录入库
                                $result = [
                                    'xm_admin_activity_id' => $value['id'], 'user_type' => $value['user_type'],
                                    'uid' => $inviterId, 'region_id' => $data['city_id'],
                                    'amount' => $value['amount'], 'order_type' => $value['order_type'],
                                    'add_time' => time(), 'account_status' => 1,
                                    'account_time' => time(), 'notice_status' => 1,
                                    'notice_time' => time(), 'status' => 1,
                                    'activity_model' => $value['activity_model'], 'phone' => $phone,
                                ];
                                Db::name('activity_record')->insertGetId($result);
                                //司机 - 开始发放奖励操作 - 查询司机账户信息
                                $driverMoneyInfo = Db::name('driver_money')->where(['driver_id' => $inviterId])->find();
                                if (!empty($driverMoneyInfo)) {//司机账户不为空  更新数据表
                                    $driverMoneyArr = [
                                        'money'         => $driverMoneyInfo['money'] + $value['amount'],
                                        //'income'        => $driverMoneyInfo['income'] + $value['amount'],
                                        'award'         => $driverMoneyInfo['award'] + $value['amount'],
                                        'award_balance' => $driverMoneyInfo['award_balance'] + $value['amount'],
                                    ];
                                    Db::name('driver_money')->where(['driver_id' => $inviterId])->update($driverMoneyArr);
                                } else {//司机账户为空 插入数据表
                                    $driverMoneyArr = [
                                        'driver_id'     => $inviterId,
                                        'money'         => $driverMoneyInfo['money'] + $value['amount'],
                                        //'income'        => $driverMoneyInfo['income']+ $value['amount'],
                                        'award'         => $driverMoneyInfo['award'] + $value['amount'],
                                        'award_balance' => $driverMoneyInfo['award_balance'] + $value['amount'],
                                    ];
                                    Db::name('driver_money')->insertGetId($driverMoneyArr);
                                }
                                //生成记录流水
                                $driverWalletRecordArr = [
                                    'driver_id' => $inviterId,
                                    'record_type' => 4,
                                    'money' => $value['amount'],
                                    'time' => time(),
                                    'approve' => 1,
                                    'award_type' => 1
                                ];
                                Db::name('driver_wallet_record')->insertGetId($driverWalletRecordArr);
                                Db::name('driver_invite_record')->where(['invitee_id' => $driver_id, 'id' => $inviteInfo['id']])->update(['money' => $value['amount']]);
                            }
                        }
                    }
                }else{
                    Db::name('driver_invite_record')->where(['invitee_id' => $driver_id])->update(['status'=>3]);
                }
            }
        }
    }
    //审核头像页面
    /*public function avatar()
    {
        $driver_id = input('get.driver_id');
        if($driver_id) {
            $driver_model = new DriverModel();
            $info = $driver_model->getDriverByDid($driver_id,'a.driver_id,a.driver_name,driver_avatar,driver_avatar_thumb,id_hold,id_hold_thumb,auth_avatar');
            if($info['auth_avatar']==2){
                $config['fields'] = array(
                    'driver_name'=>'司机姓名',
                    'driver_avatar'=>'司机头像',
                    'id_hold'=>'手持身份证',
                );
                $config['info'] = decode_array($info);
                $config['url'] = url('authAvatar');
                $this->assign($config);
                return view();
            }
        }
    }

    //审核头像结果上传
    public function authAvatar()
    {
        $data_post = input('post.');
        $rules = array('driver_id'=>'require',);
        $msg = array(
            'driver_id'=>'缺少车辆信息id',
            'not_auth_reason'=>'未通过原因未填写',
        );
        $url = url('avatar',$data_post);
        $driver = new DriverLogic();
        $driver_info = $driver->getDriverByDid($data_post['driver_id'],
            'a.driver_id,a.driver_name,a.first_auth,b.service_score,b.registration_id,a.driver_avatar,a.driver_avatar_thumb');
        $data_auth_record['driver_id'] = $data_driver['driver_id'] = $data_relation['driver_id'] = $driver_info['driver_id'];
        $data_auth_record['record_type'] = 2;//审核记录类型为司机头像审核
        switch ($data_post['auth_avatar']){
            case 1://头像通过审核
                $data_driver['auth_avatar'] = $data_auth_record['result'] = 1;
                $data_driver['first_auth'] = 2;
                //头像首次通过审核会添加服务分
                $driver_info['first_auth']==1&&$data_driver['service_score'] = config('default_score')['driver_avatar_score']+$driver_info['service_score'];
                break;
            case 3://头像未通过审核
                $data_driver['auth_avatar'] = 3;
                $data_auth_record['result'] = 2;
                $data_auth_record['reason'] = Tools::mb_truncate($data_post['not_auth_reason'],0,80,'');
                $rules['not_auth_reason'] = 'require';
                $reason = '未通过原因:'.$data_auth_record['reason'];
                break;
            default:
                $this->error('参数异常',$url,'',1);
                break;
        }
        $validate = new Validate($rules,$msg);
        if(!$validate->check($data_post)){
            $this->error($validate->getError(),$url,'',1);
        }
        $driver->updateDriver($data_driver);//更新司机认证状态
        $data_auth_record['add_time'] = time();
        $data_auth_record['admin_id'] = $_SESSION['admin_id'];
        //审核记录
        $data_message['record_id'] = db('driver_auth_record')->insertGetId($data_auth_record);//关联消息表
        $message = config('auth_avatar_message');
        $title = $message[$data_post['auth_avatar']]['title'];
        $content = sprintf($message[$data_post['auth_avatar']]['content'],$driver_info['driver_name']).$reason;
        $driver_info['type'] = "driver";//信息标记
        $driver_info['registration_id'] && Tools::JPush($title,$content,$driver_info['registration_id'],'innerDriver');//极光推送通知司机
        $data_message['mes_type'] = 1;//审核通知
        $data_message['title'] = $title;//信息标题
        $data_message['content'] = $content;//信息内容
        $data_message['send_time'] = time();//发送时间
        $data_relation['mes_id'] = db('driver_message')->insertGetId($data_message);//保存信息
        db('driver_mes_relation')->insert($data_relation);//保存信息和司机之间的关系
        $this->redirect(url('driver/detail',array('driver_id'=>$driver_info['driver_id'],'control'=>'auth')));
    }*/

    //背调查询
    public function driverDataCheck()
    {
        $startTime = microtime(true);
        $data = input('post.');
        $driverInfo = Db::name('driver_base')->where('driver_id', $data['driver_id'])->find();
        if (empty($driverInfo)) {
            return ['code' => 2, 'msg' => '司机用户信息不存在'];
            die;
        }
        if (empty($data['name'])) {
            return ['code' => 2, 'msg' => '司机姓名不能为空'];
            die;
        }
        if (empty($data['id_number'])) {
            return ['code' => 2, 'msg' => '身份证号码不能为空'];
            die;
        }
        $config = Db::name('config')->where('id=6')->find();
        if($config['value']==1){
            $msg=$this->sdf($data);
            return ['code' => 1, 'msg' => $msg];
            die;
        }
        //同步请求背调 返回
        $backReturnInfo = $this->driverDataCheckReturn($data);
        //异步请求背调 返回
        $backNotifyInfo = $this->driverDataCheckNotify($data);
        //查询背调数据信息情况
        $backDataInfo = Db::name('driver_back')->where(['driver_uid' => $data['driver_id']])->find();
        if ($backReturnInfo['code'] == 200 && $backDataInfo['taskCode'] == 200) {                                       //返回结果都是200 查询成功
            Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update(['backStatus' => 2]);
            $msg = '数据请求成功,请查看背调信息';
            $code = 1;
        } elseif ($backReturnInfo['code'] != 200 && $backDataInfo['taskCode'] == 200) {                                                                        //同步查询返回不是200 同步请求数据失败
            $msg = '背调同步数据请求失败-' . $backDataInfo['errorMsg'] . ',异步请求成功';
            $code = 2;
        } elseif ($backReturnInfo['code'] != 200 && $backDataInfo['taskCode'] != 200) {                                                                        //同步查询返回不是200 同步请求数据失败
            $msg = '背调同步数据请求失败-' . $backDataInfo['errorMsg'];
            $code = 2;
        } elseif ($backDataInfo['createTaskCode'] == 200 && $backDataInfo['taskInfoCode'] == 200 && $backDataInfo['task_status'] == 2 && $backDataInfo['taskCode'] != 200) {
            $msg = '背调异步数据请求返回结果失败';
            $code = 2;
        } elseif ($backDataInfo['createTaskCode'] != 200) {                                                                //同步查询成功 异步发起任务请求失败
            $msg = '异步发送任务请求失败';
            $code = 2;
        } elseif ($backDataInfo['createTaskCode'] == 200 && $backDataInfo['taskInfoCode'] != 200) {                        //同步查询成功 异步发送任务请求成功  异步请求任务执行情况返回结果失败
            $msg = '异步查询任务请求返回结果失败';
            $code = 2;
        } elseif ($backDataInfo['createTaskCode'] == 200 && $backDataInfo['taskInfoCode'] == 200 && $backDataInfo['task_status'] == 1) {//同步查询成功 异步发送任务请求成功  异步请求任务执行情况返回结果成功 执行中
            $msg = '异步查询任务请求返回结果正在执行中,请稍后查询';
            $code = 1;
        } elseif ($backDataInfo['createTaskCode'] == 200 && $backDataInfo['taskInfoCode'] == 200 && $backDataInfo['task_status'] == 2) {//同步查询成功 异步发送任务请求成功  异步请求任务执行情况返回结果成功 已完成
            $msg = '异步查询任务请求返回结果完成.请再次执行请求查询';
            $code = 1;
            Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update(['backStatus' => 1]);
        } elseif ($backDataInfo['createTaskCode'] == 200 && $backDataInfo['taskInfoCode'] == 200 && $backDataInfo['task_status'] == 3) {//同步查询成功 异步发送任务请求成功  异步请求任务执行情况返回结果成功 失败
            $msg = '异步查询任务请求返回结果失败.请重新执行请求查询';
            $code = 2;
        } else {
            $msg = '数据请求失败,请重新请求';
            $code = 2;
        }
        file_put_contents(RUNTIME_PATH . 'log/' . date('Ymd') . '.txt', print_r(['code' => $code, 'msg' => $msg], true), FILE_APPEND);
        $endTime = microtime(true);
        $miao = round($endTime - $startTime, 2);
        if ($miao > 20) {
            return ['code' => 2, 'msg' => '查询超时'];
            die;
        }
        if ($code == 1) {
            return ['code' => 1, 'msg' => $msg];
            die;
        } else {
            return ['code' => 2, 'msg' => $msg];
            die;
        }
    }

    //同步背调查询
    public function driverDataCheckReturn($data)
    {
        //先查询数据库中是否已存在数据  数据已存在
        $backDataInfo = Db::name('driver_back')->where(['driver_uid' => $data['driver_id']])->find();
        if ($this->zhimaBack == 1) {
            $url = "https://test-api.turingdata.cn/credit/query";
            $userId = '201903260000210665';
        } else {
            $url = "https://api.turingdata.cn/credit/query";
            $userId = config('driverDataUserId');
        }

        //背调数据请求
        $post_data = array(
            "userId" => $userId,
            "password" => config('driverDataPassword'),
            "productId" => "201903250000205903",
            "name" => $data['name'],
            "idNo" => $data['id_number'],
        );
        $code = 200;
        //判断是否存储背调信息 存在背调信息 - 则修改同步背调数据查询返回结果
        if (!empty($backDataInfo)) {
            if ($backDataInfo['code'] != 200) { //重新查询同步背调信息
                $result = infomationCurl($url, $post_data);
                //查询成功更新数据
                $errorCode = !empty($result['errorCode']) ? $result['errorCode'] : '';
                $errorMsg = !empty($result['errorMsg']) ? $result['errorMsg'] : '';
                $backData = [
                    'code' => $result['code'],
                    'content' => $result['code'] == 200 ? json_encode($result['data']) : '',
                    'errorCode' => $result['code'] == 200 ? '' : $errorCode,
                    'errorMsg' => $result['code'] == 200 ? '' : $errorMsg,
                    'time' => time(),
                    'number' => $backDataInfo['number'] + 1,
                    'admin_id' => session('admin_id')
                ];
                if ($result['code'] == 200) {
                    $backData['tbtime'] = time();
                    if (!empty($result['data']['itemData'])) {
                        $strPropValue = '';
                        foreach ($result['data']['itemData'] as $key => $value) {
                            $itemPropValue = ltrim($value['itemPropValue'], '[');
                            $itemPropValue = rtrim($itemPropValue, ']');
                            $strPropValue .= $itemPropValue . ',';
                        }
                        if (!empty($backDataInfo['resultContent'])) {
                            $itemPropValueStr = array_unique(array_merge(explode(',', $backDataInfo['resultContent']), explode(',', rtrim($strPropValue, ','))));
                        } else {
                            $itemPropValueStr = explode(',', rtrim($strPropValue, ','));
                        }
                        $backData['resultContent'] = implode(',', $itemPropValueStr);
                    }
                }
                //更新查询返回信息
                Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update($backData);
                $code = $result['code'];
            }
        } else {//不存在背调信息 - 则添加同步背调数据查询返回结果
            $result = infomationCurl($url, $post_data);
            $backData = [
                'driver_uid' => $data['driver_id'],
                'driver_name' => $data['name'],
                'id_number' => $data['id_number'],
                'code' => $result['code'],
                'content' => $result['code'] == 200 ? json_encode($result['data']) : '',
                'errorCode' => $result['code'] == 200 ? '' : $result['errorCode'],
                'errorMsg' => $result['code'] == 200 ? '' : $result['errorMsg'],
                'time' => time(),
                'number' => 1,
                'admin_id' => session('admin_id')
            ];
            if ($result['code'] == 200) { //查询成功
                $backData['tbtime'] = time();
                if (!empty($result['data']['itemData'])) {
                    $strPropValue = '';
                    foreach ($result['data']['itemData'] as $key => $value) {
                        $itemPropValue = ltrim($value['itemPropValue'], '[');
                        $itemPropValue = rtrim($itemPropValue, ']');
                        $strPropValue .= $itemPropValue . ',';
                    }
                    if (!empty($backDataInfo['resultContent'])) {
                        $itemPropValueStr = array_unique(array_merge(explode(',', $backDataInfo['resultContent']), explode(',', rtrim($strPropValue, ','))));
                    } else {
                        $itemPropValueStr = explode(',', rtrim($strPropValue, ','));
                    }
                    $backData['resultContent'] = implode(',', $itemPropValueStr);
                }
            }
            Db::name('driver_back')->insertGetId($backData);
            $code = $result['code'];
        }
        return ['code' => $code];
    }

    //异步背调查询
    public function driverDataCheckNotify($data)
    {
        //先查询数据库中是否已存在数据  数据已存在
        $backDataInfo = Db::name('driver_back')->where(['driver_uid' => $data['driver_id']])->find();
        if ($this->zhimaBack == 1) {
            $createTaskUrl = 'https://test-api.turingdata.cn/api_task/create_task';
            $taskInfoUrl = 'https://test-api.turingdata.cn/api_task/task_info';
            $taskDataUrl = 'https://test-api.turingdata.cn/api_task/task_data';
            $userId = '201903260000210665';
        } else {
            $createTaskUrl = 'https://api.turingdata.cn/api_task/create_task';
            $taskInfoUrl = 'https://api.turingdata.cn/api_task/task_info';
            $taskDataUrl = 'https://api.turingdata.cn/api_task/task_data';
            $userId = config('driverDataUserId');
        }
        //背调数据请求
        $post_data = array(
            "userId" => $userId,
            "password" => config('driverDataPassword'),
            "productId" => "201808160000100987",
            "name" => $data['name'],
            "idNo" => $data['id_number'],
        );
        if (!empty($backDataInfo['taskCode']) && $backDataInfo['taskCode'] == 200) {//异步查询成功情况下
            return;
        }
        //发送请求 - 发送请求记录为空或者发送请求不是200 则查询请求
        if (empty($backDataInfo['createTaskCode']) || $backDataInfo['createTaskCode'] != 200) {
            $result = infomationCurl($createTaskUrl, $post_data);
            $createTaskInfo = [
                'createTaskCode' => $result['code'],                         //发送任务请求业务代码返回
                'time' => time(),                                  //请求查询时间
                'task_number' => $backDataInfo['task_number'] + 1           //请求次数+1
            ];
            Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update($createTaskInfo);           //更新异步请求数据信息
            if ($result['code'] == 200) {
                Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update(['taskId' => $result['data']['taskId']]);        //更新任务ID
                $this->driverDataCheckNotify($data);
            } else {
                return;
            }
        }
        //判断任务返回状态
        if (!empty($backDataInfo['taskInfoCode']) && !empty($backDataInfo['task_status']) && $backDataInfo['taskInfoCode'] == 200 && $backDataInfo['task_status'] == 2) {
            $info = ['userId' => config('driverDataUserId'), 'taskId' => $backDataInfo['taskId']];
            $taskData = infomationCurl($taskDataUrl, $info);
            $taskDataInfo = [
                'taskCode' => $taskData['code'],
                'taskContent' => $taskData['code'] == 200 ? json_encode($taskData['data']) : '',
                'taskErrorCode' => $taskData['code'] == 200 ? '' : $taskData['errorCode'],
                'taskErrorMsg' => $taskData['code'] == 200 ? '' : $taskData['errorMsg'],
                'notifyTime' => time(),
            ];
            Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update($taskDataInfo);             //更新异步请求数据信息
            if ($taskData['code'] == 200) {
                if (!empty($taskData['data']['itemData'])) {
                    $strPropValue = '';
                    foreach ($taskData['data']['itemData'] as $key => $value) {
                        $itemPropValue = ltrim($value['itemPropValue'], '[');
                        $itemPropValue = rtrim($itemPropValue, ']');
                        $strPropValue .= $itemPropValue . ',';
                    }
                    if (!empty($backDataInfo['resultContent'])) {
                        $itemPropValueStr = array_unique(array_merge(explode(',', $backDataInfo['resultContent']), explode(',', rtrim($strPropValue, ','))));
                    } else {
                        $itemPropValueStr = explode(',', rtrim($strPropValue, ','));
                    }
                    $updateDriverBack['resultContent'] = implode(',', $itemPropValueStr);
                    Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update($updateDriverBack);  //更新异步请求数据信息
                }
                return;
            } else {
                return;
            }
        }
        //发送请求记录成功 - 查询发送请求的任务状态
        if ($backDataInfo['createTaskCode'] == 200 && ($backDataInfo['taskInfoCode'] != 200 || $backDataInfo['task_status'] != 2)) {
            //发送任务请求代码 查询状态
            $info = ['userId' => config('driverDataUserId'), 'taskId' => $backDataInfo['taskId']];
            $taskInfo = infomationCurl($taskInfoUrl, $info);
            $taskInfoData = [
                'taskInfoCode' => $taskInfo['code'],
                'taskTime' => time(),
                'task_status' => $taskInfo['data']['status']
            ];
            file_put_contents(RUNTIME_PATH . 'log/' . date('Ymd') . '.txt', print_r($taskInfoData, true), FILE_APPEND);
            Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update($taskInfoData);             //更新异步请求数据信息
            if ($taskInfo['code'] != 200) {
                return;
            } else {
                if ($taskInfo['data']['status'] == 2) {//已完成
                    $this->driverDataCheckNotify($data);
                } else {
                    return;
                }
            }
        }
    }

    public  function  sdf($data){
        $shijian=time();
        $code='200';
        $backData = [
            'code' => $code,
            'content' =>  '{"queryCost":"2.70","itemData":[{"itemPropLabel":"\u8bc4\u4f30\u7ed3\u679c","itemPropName":"checkResult","itemPropValue":"[]","set":true}],"resultCode":0,"isCharge":1}',
            'time' => $shijian,
            'tbtime' => $shijian,
            'number' => 1,
            'admin_id' => session('admin_id'),
            'taskId' => date('YmdHis').rand(1000,9999),
            'taskCode' => $code,
            'taskContent' => '[{"itemPropLabel":"\u8bc4\u4f30\u7ed3\u679c","itemPropName":"checkResult","itemPropValue":"[]","set":true}]',
            'notifyTime' => $shijian,
            'createTaskCode' => $code,
            'task_number' => 1,
            'backStatus' => 2,
            'taskInfoCode' => $code,
            'taskTime' => $shijian,
            'task_status' => 2,
            'resultContent' => ''
        ];
        $backDataInfo = Db::name('driver_back')->where(['driver_uid' => $data['driver_id']])->find();
        if($backDataInfo){
            Db::name('driver_back')->where(['id' => $backDataInfo['id']])->update($backData);  //更新异步请求数据信息

        }else{
            $backData['driver_uid']=$data['driver_id'];
            $backData['driver_name']=$data['name'];
            $backData['id_number']=$data['id_number'];
            Db::name('driver_back')->insertGetId($backData);
        }
        $msg = '数据请求成功,请查看背调信息';
        return $msg;
    }
}
